<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>第二天拜访计划</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=e9c5bb62">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=66b457d6">
    <style>
        table input{
            border:none;
            width: 100%;
        }
    </style>
</head>
<body>
<section class="content"  id="app">
    <table class="table  table-bordered text-center" id="week">
        <tr>
            <td>日期</td>
            <td>客户名称</td>
            <td>上次拜访时间</td>
            <td>客户地点</td>
            <td>客户行业</td>
            <td>意向设备</td>
            <td>备注</td>
            <td v-if="new Date().getDay()==0">操作</td>
        </tr>
        <tr v-for="(item,i) in list">
            <td :rowspan="item.weekNamespan" :class="{hidden: item.weekNamedis}">{{item.weekName}}</td>
            <td><input type="text" v-model="item.customerName" v-if="new Date().getDay()==0">
                <span v-else>{{item.customerName}}</span></td>
            <td><input type="text" v-model="item.lastVisitTime"v-if="new Date().getDay()==0">
                <span v-else>{{item.lastVisitTime}}</span></td>
            <td><input type="text" v-model="item.customerAddress"v-if="new Date().getDay()==0">
                <span v-else>{{item.customerAddress}}</span></td>
            <td><input type="text" v-model="item.customerIndustry"v-if="new Date().getDay()==0">
                <span v-else>{{item.customerIndustry}}</span></td>
            <td><input type="text" v-model="item.intentionDevice"v-if="new Date().getDay()==0">
                <span v-else>{{item.intentionDevice}}</span></td>
            <td><input type="text" v-model="item.remake"v-if="new Date().getDay()==0">
                <span v-else>{{item.remake}}</span></td>
            <td v-if="new Date().getDay()==0"><input type="text" ><a @click="del(item.id)" id="delete" >删除</a> </td>
        </tr>


    </table>
    <input type="button" id="save" class="saveBtn btn oaBtn" @click="save" value="保存修改" style="margin-left: 500px ;margin-top: 17px">
    <input type="button" id="add" class="saveBtn btn oaBtn" @click="add" value="确认提交" style="margin-left: 30px ;margin-top: 17px;">


    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=0b5caf39"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=0c4d95a9"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript">
    console.log(urlConfig);
    var app = new Vue({
        el:'#app',
        data:{
            list:[],
            week:[]
        },
        methods:{
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getWeek:function() {
                var that=this;
                const week = [];
                for (var i = 0; i < 6; i++) {
                    var Stamp = new Date();
                    var num = 7-Stamp.getDay() + 1 + i;
                    Stamp.setDate(Stamp.getDate() + num);
                    var mvar ='';
                    if((Stamp.getMonth() + 1)>10){
                        mvar = (Stamp.getMonth() + 1);
                    }else{
                        mvar =  '0' + (Stamp.getMonth() + 1);
                    }
                    var dvar ='';
                    if( Stamp.getDate()<10){
                        dvar = '0' +  Stamp.getDate();
                    }else{
                        dvar =  Stamp.getDate()+'';
                    }
                    if((Stamp.getMonth() + 1)>10){}else{}
                    week[i] = Stamp.getFullYear()+'-'+mvar +'-'+ dvar;
                    console.log(week[i]);
                }
                that.week=week;
            },
            initData:function () {
                var that=this;
                that.getWeek();
                var list=[
                    {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[0],
                        "weekName":"星期一"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[0],
                        "weekName":"星期一"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[0],
                        "weekName":"星期一"
                    },{
                        "createTime": "",
                        "createUserId":getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[1],
                        "weekName":"星期二"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[1],
                        "weekName":"星期二"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[1],
                        "weekName":"星期二"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[2],
                        "weekName":"星期三"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[2],
                        "weekName":"星期三"
                    },{
                        "createTime": "",
                        "createUserId":getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[2],
                        "weekName":"星期三"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[3],
                        "weekName":"星期四"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[3],
                        "weekName":"星期四"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[3],
                        "weekName":"星期四"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[4],
                        "weekName":"星期五"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[4],
                        "weekName":"星期五"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[4],
                        "weekName":"星期五"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[5],
                        "weekName":"星期六"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[5],
                        "weekName":"星期六"
                    },{
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry":"",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[5],
                        "weekName":"星期六"
                    }

                ]
                this.list=this.tablesMergeCell(list);
            },

            refreshWeek: function () {
                var that = this;
                $.wyui.postMethod('/weekPlan/getWeek.json', {createUserId:getCurrentUser().id,}, function (r) {
                    console.log(r);
                    that.list = r.records;
                    this.list=that.tablesMergeCell(that.list);
                })
            },
            del:function (weekId) {
                if (confirm('确认要删除吗？')) {
                    var that = this;
                    $.wyui.postMethod('/weekPlan/removeById.json', {id: weekId}, function (r) {
                        console.log(r);
                        if(r.records=="删除成功"){
                            alert("删除成功");
                            that.refreshWeek();}

                    });
                }
            },
            add:function () {
                var that = this;
                $.wyui.postMethod('/weekPlan/add.json', that.list, function (r) {
                    console.log(r);
                    that.refreshWeek();
                })
            },
            save:function () {
                var that = this;
                $.wyui.postMethod('/weekPlan/update.json', that.list, function (r) {
                    console.log(r);
                    if(r.records=="修改成功"){
                        alert("修改成功");
                        that.refreshWeek();}
                })
            }},
        mounted:function () {
            var dt = new Date();
            var that = this;
            console.log(dt.getDay())
            if( dt.getDay()==0){
                this.initData();
            }else{
                $("#save").hide();
                $("#add").hide();
                that.refreshWeek();

            }
            console.log(this.list)

        }
    });
</script>

</body>
</html>